package pro.softzhang.algo.lc6200;

import pro.softzhang.algo.common.Utils;
import pro.softzhang.algo.flag.book.BWeekMatch;
import pro.softzhang.algo.flag.knowledge.KBitManipulation;

import java.util.stream.IntStream;

@KBitManipulation
@BWeekMatch(314)
public class LC6201_FindTheOriginalArrayOfPrefixXor {
    public static void main(String[] args) {
        int[] pref = {5,2,0,3,1};
        // [5,7,2,3,2]
        int[] arr = new Solution().findArray(pref);
        Utils.printArr(arr);
    }

    static class Solution {
        public int[] findArray(int[] pref) {
            int[] arr = new int[pref.length];
            arr[0] = pref[0];
            int t = arr[0], xor = arr[0];
            for(int i = 1; i < pref.length; i++) {
                t = pref[i];
                xor ^= t;
                arr[i] = t;
            }
            return arr;
        }
    }

    static class Solution1 {
        public int hardestWorker(int n, int[][] logs) {
            return logs[IntStream.range(0, logs.length).boxed()
                    .min((o, p) -> logs[o][1] - (o > 0 ? logs[o - 1][1] : 0) == logs[p][1] - (p > 0 ? logs[p - 1][1] : 0)
                            ? logs[o][0] - logs[p][0]
                            : logs[p][1] - (p > 0 ? logs[p - 1][1] : 0) - logs[o][1] + (o > 0 ? logs[o - 1][1] : 0))
                    .get()][0];
        }
    }
}
